//
//  YZCollectionViewCell.m
//  kuaiyi
//
//  Created by WGP on 16/5/6.
//
//

#import "YZCollectionViewCell.h"
#import "YZNetWorkTool.h"
#import "YZDoctorModel.h"

@interface YZCollectionViewCell ()

@property(nonatomic,assign)NSInteger index;
@property(nonatomic,strong)UILabel *label;

@end
@implementation YZCollectionViewCell

/*请求地址: http://iosapi.itcast.cn/doctor/doctorReceivingSetting.json.php
 http://iosapi.itcast.cn/doctor/getIntroduction.json.php
 请求地址: http://iosapi.itcast.cn/doctor/doctorDuties.json
 
 请求参数:{"doctor_id":300000315}
 */


-(instancetype)initWithIndex:(NSInteger)index
{
    if (index == 0) {
        
        YZCollectionViewCell *cell = [[YZCollectionViewCell alloc] init];
        UILabel *label = [[UILabel alloc] init];
        label.backgroundColor = [UIColor brownColor];
        self.index = index;
        self.label = label;
        label.numberOfLines = 0;
        [cell.contentView addSubview:label];
        
        label.frame = cell.bounds;
        return cell;
        
    }else if(index == 1)
    {

    }
    else if (index == 2)
    {
        
    }
    return nil;
}

-(void)setDoctorModel:(YZDoctorModel *)doctorModel
{
    _doctorModel = doctorModel;
    
    if (self.index == 0) {
        NSString *URL = @"http://iosapi.itcast.cn/doctor/doctorReceivingSetting.json.php";
        NSDictionary *parameters = @{@"doctor_id":self.doctorModel.doctor_id};
        [[YZNetWorkTool sharedNetWorkTool] POST:URL parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            NSDictionary *dict = (NSDictionary *)responseObject;
            NSDictionary *data = dict[@"data"];
            NSString *receiving_setting_extra = data[@"receiving_setting_extra"];
            NSArray *receiving_settingsArr = dict[@"receiving_settings"];
            
            NSMutableString *receiving_settings = [NSMutableString string];
            for (NSString *str in receiving_settingsArr) {
                NSString *string = [NSString stringWithFormat:@"%@ ",str];
                [receiving_settings appendString:string];
            }
            
            NSString *text = [NSString stringWithFormat:@"%@\n%@",receiving_setting_extra,receiving_settings];
            NSRange range = [text rangeOfString:receiving_setting_extra];
            NSMutableAttributedString *attM = [[NSMutableAttributedString alloc] initWithString:text];
            [attM addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range];
            self.label.attributedText = attM;
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];
    }
}

@end





